
import * as constant from '../constant'

import request from '../request'

// 注册提交
export const getProfile = (username) => {
    return async (dispatch) => {
        try {
            // 网络请求
            const result = await request.profile.get(username)
            // 成功 status 1
            console.log("action result", result);
            dispatch({ type: constant.PROFILE_GET_RESULT, result })

        } catch (error) { // 错误
            console.log(error);
            dispatch({ type: constant.USER_SYNC_RESULT, result: { status: 0, message: error.message, errors: error.errors } })
        }

    }
}
export const profileUnload = () => {
    return { type: constant.PROFILE_UNLOAD }
}

// UI - action  - profile - apiClient - api - app - route -controller -model - mysql
//                   dispatch -
export const addFollow = (username) => {
    return async (dispatch) => {
        try {
            const result = await request.profile.follow(username)
            console.log("action result ", result);
            dispatch({ type: constant.PROFILE_FOLLOW_RESULT, result })
        } catch (error) {
            console.log(error);
            dispatch({ type: constant.PROFILE_FOLLOW_RESULT, result: { status: 0, message: error.message, errors: error.errors } })

        }
    }
}
export const unFollow = (username) => {
    return async (dispatch) => {
        try {
            const result = await request.profile.unfollow(username)
            console.log("action result ", result);
            dispatch({ type: constant.PROFILE_FOLLOW_RESULT, result })
        } catch (error) {
            console.log(error);
            dispatch({ type: constant.PROFILE_FOLLOW_RESULT, result: { status: 0, message: error.message, errors: error.errors } })

        }
    }
}





